<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MVCWeb.Models.DocCategory>>" %>

<%@ Register Src="~/Views/Menu/MainMenu.ascx" TagName="MainMenu" TagPrefix="mmuc" %>

<%@ Register Src="~/Views/Shared/LogOnUserControl.ascx" TagName="LogOnUserControl" TagPrefix="louc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title><%= System.Configuration.ConfigurationManager.AppSettings["SiteName1"] %> - Community</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script language="javascript" type="text/javascript">
        function ChangeStatus(id, name, status) {
            var s = 'active';
            if (status.toString() == "True") {
                s = 'deactive';
            }
            if (confirm("Are you sure that this document: " + name + " will be " + s + "?")) {
                // Perform change status.
                var action = '<%= Url.Action("ChangeStatus", "Doc") %>/' + id;
                var request = new Sys.Net.WebRequest();
                request.set_httpVerb("POST");
                request.set_url(action);
                request.add_completed(ChangeStatusCompleted);
                request.invoke();
            }
        }

        function ChangeStatusCompleted() {
            // Reload page  
            window.location.reload();
        }    
    </script>

    <louc:LogOnUserControl ID="LogOnUserControl1" runat="server" />
    <!-- BEGIN: MainMenu -->
    <mmuc:MainMenu ID="MainMenu1" runat="server" />
    <!-- END: MainMenu -->
    <br />
    <%--<h2>
        Community:
        <%= ViewData["CommunityName"] == null ? string.Empty: ViewData["CommunityName"].ToString() %></h2>--%>
    <% foreach (var category in Model)
       { %>
    <fieldset>
        <legend>
            <%= Html.Encode(category.Category) %>
        </legend>
        <br />
        <table id="document">
            <tr>
                <% if (HttpContext.Current.User.IsInRole("Administrators"))
                   { %>
                <th>
                </th>
                <th>
                </th>
                <% } %>
                <th>
                    Title
                </th>
                <th>
                    Modified Date
                </th>
                <th>
                    Size (Kb)
                </th>
                <th>
                </th>
            </tr>
            <% foreach (var item in category.Docs)
               { %>
            <tr>
                <% if (HttpContext.Current.User.IsInRole("Administrators"))
                   { %>
                <td>
                    <a href='<%= Url.Action("Edit", "Doc", new { id = item.DocId })%>'>Edit </a>
                </td>
                <td>
                    <a onclick="ChangeStatus(<%=item.DocId%>, '<%=item.Name%>', '<%=item.Active%>')"
                        href="JavaScript:void(0)">
                        <%
                            if (item.Active)
                            {
                        %>
                        Active
                        <%
                            }
                        else
                        {%>
                        Deactive
                        <%
                            }%>
                    </a>
                </td>
                <% } %>
                <td class="name">
                    <%= Html.Encode(item.Name)%>
                </td>
                <td>
                    <%= Html.Encode(item.ModifiedDate.Value.ToShortDateString()) %>
                </td>
                <td>
                    <%= (Convert.ToDouble(Html.Encode(item.Size)) / 1024).ToString("N2") %>
                </td>
                <td>
                    <a target="_blank" href='<%= item.URLLink %>'>Download</a>
                </td>
            </tr>
            <% } %>
        </table>
    </fieldset>
    <br />
    <%} %>
    <p>
        <%= Html.ActionLink("Back to categories list", "Index", "Doc", new { communityId = Request.QueryString["CommunityId"]}, null)%>
    </p>
</asp:Content>
